<?php
class Type_Enum extends Type_Abstract {
	protected $wireType = Type_Abstract::WIRETYPE_VARINT;
	protected function readImpl(IO_Reader_Interface $reader) {
		$this->value = $this->getEnumNameById($this->readWireTypeData($reader));
	}
	protected function writeImpl(IO_Writer_Interface $writer) {
		$this->writeWireTypeData($writer, $this->getEnumIdName($this->value));
	}
	
	protected function getEnumNameById($id) {
		if(isset($this->extra[$id])) {
			return $this->extra[$id];
		}
		throw new Type_Exception("Unknow value in enum");
	}
	protected function getEnumIdName($name) {
		$enums = array_flip($this->extra);
		if(isset($enums[$name])) {
			return  $enums[$name];
		}
		throw new Type_Exception("Unknow value in enum");
	}
}
?>